Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
Plotting additional points on mapquest API map results in "Uncaught TypeError: t.addLayer is not a function"

I am trying to plot locations on a map using the Mapquest API. When the page is loaded, the first script generated the map, and places it in a div, which works properly.

When I call the function "plotPoint()" to add another point on the map, I get the following error: "Uncaught TypeError: t.addLayer is not a function"

<script src="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.js"></script>

<script type="text/javascript">
    L.mapquest.key = 'KEY';
    var map;

      window.onload = function() {

        var map = L.mapquest.map('map', {
          center: [23.1596297, -82.2116596],
          layers: L.mapquest.tileLayer('map'),
          zoom: 8
        });

        L.marker([23.1596297, -82.2116596], {
          icon: L.mapquest.icons.marker(),
          draggable: false
        }).bindPopup('LOCATION 1').addTo(map);

        
      };

function plotPoint(){
        L.marker([23.1796297, -82.2416596], {
          icon: L.mapquest.icons.marker(),
          draggable: false
        }).bindPopup('LOCATION 2').addTo(map);
}
</script>

Any insight or suggestion would be most appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

map was declared as a local variable, when it should have been globally.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda